The present invention relates generally to object oriented development of database applications and more specifically to the use of chronologically overlapping transactions in a multi-threaded application.
Multi-threaded Open DataBase Connectivity (ODBC) database access has historically been accomplished through a number of complicated mechanisms. Full suites of database toolsets are available that provide Object Oriented (OO) wrappers and hundreds of objects to perform database queries. These toolsets are complicated and feature ridden. They also do not pool connections to allow for parallel transactions on separate threads. The ODBC Application Program Interface (API) can be used to write multithreaded applications, but it would require a significant amount of effort to maintain thread safety and transaction integrity. Further, as illustrated in FIGS. 1a and 1b, the ODBC API does not allow nested transactions on a single connection. Thus, using the current ODBC API, a transaction start and end must not encompass another transaction start and end. Multiple connections must be used to achieve concurrency.
Referring now to FIG. 2, an example of the difficulty inherent in synchronizing thread access to the database is shown. In this example, three separate tasks within an application require database access. In a multi-threaded environment, this is accomplished through the use of three threads in this example, each of which accesses the database independently using three separate connections to the database. Access to the database is managed by the ODBC layer. The ODBC layer interacts directly with the database management system to setup and destroy this connection. This interaction is expensive, both in terms of memory and time. The problems illustrated in FIG. 2 are typical, and could be mitigated if a more efficient connection management strategy were used. One important note is that not all the components of a given task require database access. And, some tasks require no database connection. Thus, improving the thread management strategy between the threads and the database should directly improve the development time associated with this application. In an application in which threads are employed, the complexity of the application is greatly influenced by the manner in which the threads are created and managed. Lack of a consistent thread management strategy increases the complexity of thread programming and also increases the likelihood of encountering defects related to thread complexity.
According to a method of the present, a technique for encapsulating interactions between a database application and a database that allows chronologically overlapping transactions using a single database connection in a threaded environment is disclosed. After launching the database application, one or more entities are created for the purpose of communication between the database application and the database. These entities are operable for opening one or more logical connections to the database. After the establishment of a database connection, a request for database access causes the entities to create, send and receive one or more database queries between the database application and the database.
A specialized entity of the created and initialized entities employs a mapping of one or more database application tasks contained in one or more corresponding application threads to one literal connection to the database. The number of literal connections to the database can be less than the number of tasks contained in one or more corresponding application threads in the database application. These literal connections may be pooled.
In accordance with a preferred embodiment of the method, created and initialized entities are used concurrently so that one or more database transactions may be transmitted in a chronologically overlapping fashion between the database application and the database. Object-oriented methodology, comprising environment objects, database object, database connection objects, and database query objects, is disclosed. The environment objects are used to create new database objects, and otherwise monitor the object oriented interface between the database application and the database. The database objects and database connection objects are used to facilitate interactions between the database application and the database, including assigning the literal connections to the database. The database query object sends queries to the database and receives the results of these queries.
According to the structure of an embodiment of the present invention, an encapsulation of one or more interactions between a database application and a database that allows chronologically overlapping transactions using a single database connection in a threaded environment. The structure contains a connection management layer residing below an application layer and above a database interface layer, where the database interface layer is coupled to the database. One or more threads connect the application layer to the connection management layer, where each thread contains one or more tasks. The connection management layer handles one or more connections to the database interface layer.